package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.thread.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.MemberReservationService;
import com.zzyl.nursing.vo.countByTimeVo;
import com.zzyl.serve.domain.NursingProject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 *
 * @author lzl
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class MemberReservationController extends BaseController {
    @Autowired
    private MemberReservationService memberReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        int count = memberReservationService.getCancelledReservationCount();
        return R.ok(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询指定时间段预约数量")
    public R<List<countByTimeVo>> getCountByTime() {
        List<countByTimeVo> countByTime = memberReservationService.getCountByTime();
        return R.ok(countByTime);
    }

    @PostMapping
    @ApiOperation("添加预约")
    public R<Reservation> addReservation(@RequestBody Reservation reservation) {
        boolean flag = memberReservationService.addReservation(reservation);
        return flag ? R.ok() : R.fail();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public R<TableDataInfo<Reservation>> getReservationPage(Integer status) {
        startPage();
        List<Reservation> list = memberReservationService.getReservationPage(status);
        return R.ok(getDataTable(list));
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public R cancelReservationById(@PathVariable Long id) {
        boolean flag = memberReservationService.cancelReservationById(id);
        return flag ? R.ok() : R.fail();
    }
}